%%%-------------------------------------------------------------------
%%% @author 25232
%%% @copyright (C) 2025, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 12. 11月 2025 23:14
%%%-------------------------------------------------------------------
-module(redis_worker_test).
-author("25232").

-include_lib("eunit/include/eunit.hrl").
-include("redis_driver.hrl").

write_to_file(Msg, Args) ->
  {ok, File} = file:open("redis.log", [append]),
  io:fwrite(File, Msg, Args),
  file:close(File).

start_link_test() ->
  {ok, Pid} = redis_worker:start_link("127.0.0.1", 6379, 0, "123456"),
  SetReqBin = redis_encode:encode([<<"SET">>, <<"testk">>, iolist_to_binary(json:encode(#{<<"a">> =>1,<<"b">> => <<"test">>, <<"c">> => [1,2,3]}))]),
  SetResult = gen_server:call(Pid, {request, SetReqBin}),
  ?assertEqual(SetResult, {ok, <<"OK">>}),
  GetReqBin = redis_encode:encode([<<"GET">>, <<"testk">>]),
  {ok, GetResult} = gen_server:call(Pid, {request, GetReqBin}),
  write_to_file("~p~n", [json:decode(GetResult)]),
  ok.
